home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / ndr3.exe / VERIPX.C < prev    next >
C/C++ Source or Header  |  1993-11-04  |  4KB  |  148 lines

  1. /*
  2.    VERIPX.C  shows how to obtain the IPX/SPX version number
  3.              without using Diagnostics.
  4.  
  5.    Author:  Tim Farley
  6.    Copyright 1993, Tim Farley, All Rights Reserved
  7. */
  8.  
  9. #include <stdlib.h>  /* for NULL */
  10. #include <dos.h>     /* for "GETVECT" and FP_OFF() */
  11.  
  12. #ifdef __TURBOC__
  13.    #define ASM asm
  14.    #define GETVECT getvect
  15. #else
  16.    /* assume Microsoft C if not Turbo/Borland C */
  17.    #define ASM _asm
  18.    #define GETVECT _dos_getvect
  19. #endif
  20.  
  21. /*
  22.    Pointer to the IPX entry point
  23. */
  24. static void (far * IPXentry)(void) = NULL;
  25.  
  26. /*
  27.    Pointer to the IPX signature string
  28. */
  29. static void far * IPXsignature = NULL;
  30.  
  31.  
  32. /*
  33.    DetectIPX  detects if IPX is present and fills in
  34.               the two pointers above.
  35. */
  36. static int DetectIPX( void )
  37. {
  38.    unsigned long int2Fvector;
  39.    int returnCode;
  40.  
  41.    /* if we've already been called, skip it */
  42.    if  ( NULL != IPXentry )
  43.       return ( 1 );
  44.  
  45.    /*
  46.       Make sure INT 2Fh is initialized.  This is only
  47.       technically necessary to support DOS 2.x.
  48.    */
  49.    int2Fvector = (unsigned long)GETVECT( 0x2F );
  50.    if  ( 0UL == int2Fvector )    /* No INT 2Fh handler? */
  51.       return ( 0 );              /* then no IPX!  */
  52.  
  53.    ASM {
  54.       xor   bx,bx       /* clear return registers */
  55.       mov   es,bx
  56.       mov   di,bx
  57.       mov   ax,7a00h    /* FN 7A00: Detect IPX */
  58.       int   2fh
  59.       xor   ah,ah
  60.       mov   returnCode,ax                 /* save return code */
  61.       mov   word ptr IPXentry,di          /* store API entry */
  62.       mov   word ptr IPXentry+2,es
  63.       mov   word ptr IPXsignature,bx      /* store signature */
  64.       mov   word ptr IPXsignature+2,es
  65.    }
  66.  
  67.    /*
  68.       Back up 4 bytes to point IPXsignature at the "IPX"
  69.       string.
  70.  
  71.       If we can't do that, get the signature from the
  72.       location of INT 7Ah or INT 64h.  In that case
  73.       we have to back up 6 bytes to point at "IPX".
  74.    */
  75.    if  ( FP_OFF( IPXsignature ) >= 4 )
  76.       IPXsignature = (char far *)IPXsignature - 4;
  77.    else {
  78.       IPXsignature = (char far *)GETVECT( 0x7A );
  79.       if  ( NULL == IPXsignature )
  80.          IPXsignature = (char far *)GETVECT( 0x64 );
  81.       if  ( NULL != IPXsignature )
  82.          IPXsignature = (char far *)IPXsignature - 6;
  83.    }
  84.  
  85.    return ( 0xFF == returnCode );   /* AL = FF means success */
  86. }  /* DetectIPX() */
  87.  
  88.  
  89.  
  90. /*
  91.    GetIPXVersion  obtains the address of the IPX entry point,
  92.                   and returns the IPX version number from its
  93.                   signature in RAM.
  94. */
  95. int GetIPXVersion( void )
  96. {
  97.    int verLow, verHigh;
  98.    static char sigPattern[ 4 ] = "IPX";
  99.  
  100.    if  ( !DetectIPX() )
  101.       return ( 0 );
  102.  
  103.    /*
  104.       Compare the long int (4 bytes) at the signature with
  105.       if we can't find the signature, just return 3.00
  106.    */
  107.    if  ( *( (long far *)IPXsignature ) != *( (long *)sigPattern ) )
  108.       return ( 0x300 );
  109.  
  110.    /* get the version bytes from memory */
  111.    verHigh = (int)*((unsigned char far *)IPXsignature + 4);
  112.    verLow  = (int)*((unsigned char far *)IPXsignature + 5);
  113.  
  114.    return ( ( verHigh << 8 ) | verLow );
  115. }  /* GetIPXVersion() */
  116.  
  117.  
  118. /*
  119.    GetSPXVersion()  uses the documented SPXInitialize function
  120.                     to determine if SPX is present and return
  121.                     its version number.
  122. */
  123. int GetSPXVersion( void )
  124. {
  125.    int returnCode, spxVer;
  126.  
  127.    if  ( !DetectIPX() )
  128.       return ( 0 );
  129.  
  130.    ASM {
  131.       xor   ax,ax       /* must clear AL to avoid false positive! */
  132.       mov   cx,ax
  133.       mov   dx,ax
  134.       mov   bx,0010h    /* SPX Func #10h: SPX Initialize */
  135.       call  IPXentry
  136.       xor   ah,ah
  137.       mov   returnCode,ax
  138.       mov   spxVer,bx
  139.    }
  140.  
  141.    if  ( 0xFF != returnCode )    /* if he didn't say "yes" */
  142.       return ( 0 );              /* then no SPX present */
  143.  
  144.    return ( spxVer );            /* else return the version */
  145. }  /* GetSPXVersion() */
  146.  
  147.  
  148. /* eof: VERIPX.C */